﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelperPrototype._DB
{
    class ReceiptGroupDB
    {
         public static IQueryable selectAll()
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            var query = from u in db.ReceiptGroups
                        where u.deleted ==false
                        select u;
            return query;
        }
        public static bool insert(_DB.ReceiptGroup u)
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            db.ReceiptGroups.InsertOnSubmit(u);
            db.SubmitChanges();
            return true;
        }
        public static void update(ReceiptGroup newGroup)
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            var query = (from u in db.ReceiptGroups
                         where u.ReceiptGroup_ID == newGroup.ReceiptGroup_ID
                         select u);
            if (query.Count() > 0)
            {
                ReceiptGroup ug = query.First();
                ug.ReceiptGroup_Name = newGroup.ReceiptGroup_Name;
                ug.ReceiptGroup_Status = newGroup.ReceiptGroup_Status;
                ug.Note = newGroup.Note;
                db.SubmitChanges();
                //  return query.First();
            }
          
            //return query;
        }
        public static void delete(int id)
        {
            _DB.DataClasses1DataContext db = new _DB.DataClasses1DataContext();
            var query = from u in db.ReceiptGroups
                        where u.ReceiptGroup_ID == id
                        select u;
            if (query.Count() > 0)
            {
                ReceiptGroup rg = query.First();
                rg.deleted = true;
                db.SubmitChanges();
            }
            return ;
            //return query;
        }
    }
    
}
